//
//  EFConfirmView.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/16.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFConfirmView.h"

@interface EFConfirmView()

@property(strong,nonatomic)UIView* bgView;
@property(strong,nonatomic)UIView* transparentBgView;
@property(strong,nonatomic)UIView* bodyView;
@property(strong,nonatomic)UILabel* titleLabel;
@property(strong,nonatomic)UIView* lineView;
@property(strong,nonatomic)UILabel* contentLabel;
@property(strong,nonatomic)UIButton* confirmBtn;
@end

@implementation EFConfirmView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame Title:(NSString *)title content:(NSString *)content block:(CloseBlock)close{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        [self initView];
        [self.titleLabel setText:title];
        [self.titleLabel sizeToFit];
        self.titleLabel.left = (self.bodyView.width - self.titleLabel.width)/2;
        [self.contentLabel setText:content];
        [self.contentLabel sizeToFit];
        self.contentLabel.left = 29;
        self.contentLabel.width = self.bodyView.width - 51;
        
        self.closeblock = close;
    }
    
    return self;
}

-(void)initView{
    [self.bodyView addSubview:self.titleLabel];
    [self.bodyView addSubview:self.lineView];
    [self.bodyView addSubview:self.contentLabel];
    [self.bodyView addSubview:self.confirmBtn];
    [self.bgView addSubview:self.transparentBgView];
    [self.bgView addSubview:self.bodyView];
    [self addSubview:self.bgView];
}


-(UIView *)bgView{
    if(_bgView == NULL){
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight )];
        _bgView.backgroundColor = [UIColor clearColor];
        
    }
    return _bgView;
}

-(UIView *)transparentBgView{
    if(_transparentBgView == NULL){
        _transparentBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _transparentBgView.backgroundColor = [UIColor blackColor];
        _transparentBgView.alpha = 0.6;
        
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickConfirm)];
        [self.transparentBgView addGestureRecognizer:tapGesture];
        self.transparentBgView.userInteractionEnabled  = YES;
    }
    return _transparentBgView;
}

-(UIView *)bodyView{
    if(_bodyView == NULL){
        _bodyView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth - 63 - 64 , 194)];
        _bodyView.backgroundColor = [UIColor whiteColor];
        _bodyView.left = 63;
        _bodyView.top =  (kScreenHeight - self.bodyView.width)/2;
        _bodyView.layer.masksToBounds = YES;
        _bodyView.layer.cornerRadius = 6;
        _bodyView.layer.borderWidth = 1;
        
    }
    return _bodyView;
}

-(UILabel *)titleLabel{
    if(_titleLabel == NULL){
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 85, 19)];
        _titleLabel.top = 29;
        _titleLabel.font = [UIFont systemFontOfSize:17];
        _titleLabel.textColor = kBlack333;
    }
    return _titleLabel;
}

-(UIView *)lineView{
    if(_lineView == NULL){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.bodyView.width - 50, 1)];
        _lineView.left = (self.bodyView.width - self.lineView.width)/2;
        _lineView.top = self.titleLabel.bottom + 12;
        _lineView.backgroundColor = kBlackDDD;
    }
    return _lineView;
}

-(UILabel *)contentLabel{
    if(_contentLabel == NULL){
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bodyView.width - 50, 45)];
        _contentLabel.top = self.lineView.bottom + 8;
        _contentLabel.font = [UIFont systemFontOfSize:13];
        _contentLabel.textColor = kBlack999;
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

-(UIButton *)confirmBtn{
    if(_confirmBtn == NULL){
        _confirmBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.bodyView.width - 50, 35)];
        _confirmBtn.top = self.contentLabel.bottom +   19;
        _confirmBtn.left = (self.bodyView.width - self.confirmBtn.width)/2;
        _confirmBtn.layer.masksToBounds = YES;
        _confirmBtn.layer.cornerRadius = 6;
        _confirmBtn.backgroundColor = RGBCOLOR(0x69BA45);
        _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _confirmBtn.titleLabel.textColor = [UIColor whiteColor];
        _confirmBtn.userInteractionEnabled = YES;
        [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_confirmBtn addTarget:self action:@selector(onClickConfirm) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

-(void)onClickConfirm{
    [self removeFromSuperview];
    if (self.closeblock != nil) {
        self.closeblock();
    }
}


 

@end
